<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>水平垂直居中</title>
    <style>
      /* .container {
        height: 300px;
        background-color: yellowgreen;
        display: flex;
        justify-content: center;
        align-items: center;
      } */
      .container {
        height: 300px;
        background-color: yellowgreen;
        position: relative;
      }
      /* .img {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
      } */
      .img {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 150px;
        height: 200px;
        margin-left: -75px;
        margin-top: -100px;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <img src="1.jpeg" alt="" class="img" />
    </div>
  </body>
</html>
